package com.example.lamdba;

import com.example.Employee;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

//003 练习
public class TestLambda2_1 {


    List<Employee> emps = Arrays.asList(
            new Employee("张三", 18, 9999.99),
            new Employee("李四", 38, 5555.99),
            new Employee("王五", 50, 6666.66),
            new Employee("赵六", 16, 3333.33),
            new Employee("田七", 8, 7777.77)
    );

    @Test
    public void test1() {
        Collections.sort(emps, (e1, e2) -> {
            if (e1.getAge() == e2.getAge()) {
                return e1.getName().compareTo(e2.getName());
            } else {
                return Integer.compare(e1.getAge(), e2.getAge());
            }
        });
        emps.forEach(System.out::println);

    }

    @Test
    public void test2() {
        String s1 = strHandler("\t\t\t\t 嘿嘿嘿", (s) -> s.trim());
        System.out.println(s1);
        String s2 = strHandler("abcdef", (s) -> s.toUpperCase());
        System.out.println(s2);
    }

    //需求：用于处理字符串
    public String strHandler(String str, MyFunction mf) {
        return mf.getValue(str);
    }

    @Test
    public void test3() {
        op(100L, 200L, (x, y) -> (x + y));
        op(100L, 200L, (x, y) -> (x * y));
    }

    //需求：对两个Long型数据进行处理
    public void op(Long l1, Long l2, MyFunction2<Long, Long> mf) {
        System.out.println(mf.getValue(l1, l2));
    }
}
